import { Component, OnInit, ViewChild } from '@angular/core';
import { environment } from '../../../../environments/environment';
import { ExportFileService } from '../../../core/exportFile';
import { TableCheckPageComponent } from '../../../layout/components/tableCheckPage.component';

@Component({
    selector: 'app-manufactorskill',
    templateUrl: './manufactorSkill.component.html',
    styleUrls: ['./manufactorSkill.component.less']
})
export class ManufactorSkillComponent implements OnInit {
    @ViewChild('tcp', { static: true }) tcp: TableCheckPageComponent;
    searchParam: any = {};
    headData = [];
    plainData = [];
    operaList: any = [
        { addModal: false },
        { editModal: false },
        { delModal: false }
    ];
    tempData = [];
    apiUrl: any = {};
    exportUrl = '';

    constructor(private exportFile: ExportFileService) { }

    ngOnInit() {
        this.headData = [
            { "name": "厂家技术人员名称", "width": "15%" },
            { "name": "厂家技术领域", "width": "15%" },
            { "name": "厂家技术单位名称", "width": "15%" },
            { "name": "厂家技术人员电话", "width": "15%" },
            { "name": "厂家技术人员手机", "width": "15%" },
            { "name": "厂家技术备注", "width": "" }
        ];
        this.plainData = ["person", "position", "factoryName", "phone", "cellphone", "remark"];
        this.apiUrl.add = environment.project + '/factorySupport/add';
        this.apiUrl.edit = environment.project + '/factorySupport/update';
        this.apiUrl.del = environment.project + '/factorySupport/delete';
        this.loadList();
    }
    loadList() {
        this.tcp.loadList(environment.project + '/factorySupport/query', '');
    }
    search() {
        let params = '';
        for (const item of Object.keys(this.searchParam)) {
            const data = this.searchParam[item];
            if (data || data === 0) {
                params += '&' + item + '=' + data;
            }
        }
        this.exportUrl = params;
        this.tcp.loadList(environment.project + '/factorySupport/query', params);
    }
    export() {
        this.exportFile.getDown(environment.project + '/factorySupport/export?page=1&limit=20' + this.exportUrl, '厂家技术.xls');
    }
    modalShow(type) {
        this.tempData = this.tcp.getAllData();
        this.operaList[type] = true;
    }
    modalHide(type) {
        this.operaList[type] = false;
    }
}
